import axios from "axios";
// import api from "../../api";
import {Popup, MessageBox} from 'mint-ui';

export default {
	namespaced: true,
	state: {
        goodsList: [],//查询到的发票抬头
        getBillInfor:[],//保存勾选的信息rid
        BillContent:"",//保存选择的发票大类or详情
		orderBills:[],//查询到的订单发票信息
		vals:[],//保存一个值用来点击管理返回
        newArry:[],//保存查询到的发票抬头的前两条数据
        BillBtn:'',
        shopLacks:'',//保存一个值用来表示确认订单页的商品缺失
        shopLacksFood:'',//保存一个值用来表示堂食确认订单页的商品缺失
        foodInfor1:'',//保存确认订单堂食的用户手机信息
        foodInfor2:'',//保存确认订单堂食的用户用餐信息
        shopInformation:null,//保存堂食订单的下单的商品信息
        shopInforToken:null,//保存堂食订单的下单的商品信息token值
        marks:"",//保存一个值用来表示确认订单页面的倒计时
        childOrderList:{},//保存一个值用来表示确认订单页面的倒计时
    },
	getters: {
		//操作方法
        saveBillshead(state){
            return state.goodsList;
        },
        saveBillsheadTwo(state){
            return state.newArry;
        },
        PutAShopLacks(state){
            return state.shopLacks;
        },
        PutAShopLacksFood(state){
            return state.shopLacksFood;
        },
        
      
    },
    mutations: {
    	//存储数据
    	SAVE_BILLS_HEAD(state,data){
            state.goodsList = data;
           
            // console.log(state.goodsList,"保存在vuex里面的值")
        },
        GET_BILLS_INFOR(state,data){
            state.getBillInfor = data;
            // console.log(state.getBillInfor,"保存在vuex里面的getBillInfor值")
        },
        SAVE_BILLS_CONTENT(state,data){
            state.BillContent = data;
            // console.log(state.BillContent,"保存在vuex里面的getBillInfor值")
        },
    	GET_ORDER_LIST(state, data){
            state.goodsList = data;
        },
        SAVE_BILLS_BTN(state,data){
            state.BillBtn = data;
            // console.log(state.BillContent,"保存在vuex里面的点击保存按钮值")
        },  
        GET_ORDER_BILLS(state, data){
        	state.orderBills = data;
        },
        PUT_A_VALUE(state, data){//保存一个值用来点击管理返回
        	state.vals = data;
        	// console.log(state.vals,"保存在vuex里面的vals值")
        },
        PUT_A_SHOPLACK(state, data){//保存一个值用来表示确认订单也的商品缺失
        	state.shopLacks = data;
        	// console.log(state.shopLacks,"保存在vuex里面的shopLacks值")
        },
        PUT_A_SHOPLACK_FOOD(state, data){//保存一个值用来表示堂食确认订单也的商品缺失PutAShopLackFood
        	state.shopLacksFood = data;
        	// console.log(state.shopLacks,"保存在vuex里面的shopLacks值")
        },
        SET_A_MARKS(state, data){//保存一个值用来表示确认订单页面的倒计时
        	state.marks = data;
        },
        PUT_FOOD_INFOR(state, data){//保存确认订单堂食的用户shouji信息
        	state.foodInfor1 = data;
        	// console.log(state.foodInfor1,"保存在vuex里面的foodInfor1值")
        },
        PUT_FOOD_INFORS(state, data){//保存确认订单堂食的用户用餐信息
        	state.foodInfor2 = data;
        	console.log(state.foodInfor2,"保存在vuex里面的foodInfor2值")
        },
        PUT_FOOD_SHOP_INFOR(state, data){//保存堂食订单的下单的商品信息
        	state.shopInformation = data;
        	// console.log(state.shopInformation,"保存在vuex里面的shopInformation值")
        },
        PUT_FOOD_SHOP_TOKEN(state, data){//保存堂食订单的下单的商品信息token值
        	state.shopInforToken = data;
        	// console.log(state.shopInforToken,"保存在vuex里面的shopInforToken值")
        },
        PUT_CHILD_ORDER_LIST(state, data){//保存堂食订单的信息
        	state.childOrderList = data;
        }
    },
    actions: {
    	//请求接口
    	PutAValue({commit}, data){//保存一个值用来点击管理返回
    		commit('PUT_A_VALUE', data);
        },
        PutAShopLack({commit}, data){//保存一个值用来表示确认订单也的商品缺失
    		commit('PUT_A_SHOPLACK', data);
    	},
        PutAShopLackFood({commit}, data){//保存一个值用来表示堂食确认订单也的商品缺失
    		commit('PUT_A_SHOPLACK_FOOD', data);
    	},
        PutFoodInfor({commit}, data){//保存保存确认订单堂食的用户手机信息
    		commit('PUT_FOOD_INFOR', data);
    	},
        PutFoodInfors({commit}, data){//保存确认订单堂食的用户用餐信息
    		commit('PUT_FOOD_INFORS', data);
        },
        PutFoodShopInfor({commit}, data){//保存堂食订单的下单的商品信息
    		commit('PUT_FOOD_SHOP_INFOR', data);
    	},
        PutFoodShopToken({commit}, data){//保存堂食订单的下单的商品信息token值
    		commit('PUT_FOOD_SHOP_TOKEN', data);
    	},
        PutChildOrderList({commit}, data){//
    		commit('PUT_CHILD_ORDER_LIST', data);
    	},
        setAMarks({commit}, data){//保存一个值用来表示确认订单页面的倒计时
    		commit('SET_A_MARKS', data);
    	},
    	SaveClickAddress({commit}, data) {
            commit('SAVE_BILLS_HEAD', data);
        },
        GetBillInfor({commit}, data) {
            commit('GET_BILLS_INFOR', data);
        },
        SaveBillContent({commit}, data) {
            commit('SAVE_BILLS_CONTENT', data);
        },
        SaveBillBtn({commit}, data) {
            commit('SAVE_BILLS_BTN', data);
        },
        GetBillheads({commit}){
        	var sessionId = localStorage.getItem('sessionId');
            var url = window.api.trade_host + "/orderInvoiceTitle/selectOrderInvoiceTitleList";
//			var url = "http://test.mall.yn.weilian.cn"+ api.lookUpBills;
//			var url = "http://test.mall.yn.weilian.cn/orderInvoiceTitle/selectOrderInvoiceTitleList";
            var config = {
               url,
               method: "GET",
               headers: {sessionId},
            }
            console.log("aaaaaaaavu额种族",sessionId,window.api.trade_host)
            axios(config).then((res) => {
                console.log("hahahahahahahaha", res)
                if(res.data.returnCode === 1){
//              	console.log("res.data.data", res.data.data[0].rid + "");
//					this.BillDatas = res.data.data;
//					this.dispatch('hzh/SaveClickAddress', res.data.data);
					commit('SAVE_BILLS_HEAD', res.data.data);
					res.data.data && res.data.data.forEach(ele => {
						
						ele.isDefault && commit('GET_BILLS_INFOR', ele.rid);
					})
//					this.dispatch('hzh/getGoodsDate')
					try {
	                    commit('GET_ORDER_LIST', res.data.data);
	                    
	                } catch (error) {
	                    
	                }
					
                }else if(res.data.returnCode === 0){
                	MessageBox.alert(res.data.errmsg)
//              	.then(action => {
//	                   this.$router.push('/login');
//	                });
                }
            
            })
      	},
      	GetOrderBills({commit}, data){
      		return new Promise((resolve,reject)=>{
				var sessionId = localStorage.getItem('sessionId');
	            var url = window.api.trade_host + "/orderElectronicInvoice/selectElectronicInvoice/" + data;
	            var config = {
	               url,
	               method: "GET",
	               headers: {sessionId},
	            }
	            console.log("bbbbbbbbbb9",sessionId)
	            axios(config).then((res) => {
	                console.log("uuuuuuuuuuuiiiiiiii", res)
	                if(res.data.returnCode === 1){
//						this.BillDetails = res.data.data[0];
						try {
                            commit('GET_ORDER_BILLS', {
                                data:res.data.data[0],
                                returnCode:1
                            });
		                } catch (error) {
		                    
		                }
//						this.$store.dispatch('hzh/SaveClickAddress', res.data.data);
						resolve(true)
	                }else if(res.data.returnCode === 0){
                        
                            // this.BillDetails = res.data.data[0];
                            // commit('GET_ORDER_BILLS', res.data.data[0]);
                            commit('GET_ORDER_BILLS', {
                                data:undefined,
                                returnCode:0
                            });
                        
	                	resolve(false)
//	                	MessageBox.alert(res.data.msg)
//	                	.confirm(res.data.errmsg).then(action => {
//		                   this.$router.push('/login');
//		                });
	                }else if(res.data.returnCode === 2){
                        commit('GET_ORDER_BILLS', {
                            data:undefined,
                            returnCode:2
                        });
	                	resolve(false)

                    }else if(res.data.returnCode === 3){
                        commit('GET_ORDER_BILLS', {
                            data:undefined,
                            returnCode:3
                        });
	                	resolve(false)

                    }
	            
	            })
            })
        },
          
    }
	
	
	
}
